package main

import (
	"fmt"
	"math/rand"
	"strconv"
	"time"
)

const (
	a = iota + 1000 //1001
	b               // +1
	c
	d
	e
)

func init() {
	rand.Seed(time.Now().UnixNano())
}

func main() {
	fmt.Println(cReturn())
	/*a := 100
	fmt.Printf("4位数%06d\n", a)*/
	//fmt.Println(a, b, c, d, e)
	s2 := "你好"
	s3 := []rune(s2) //转成字符切片
	str := `
dsf sngi sag isda fs 
sdfasdgfsa fsadf 
		`
	m := map[int]int{
		1: 1,
		2: 2,
	}

	s3[0] = 's'
	fmt.Println(string(s3), str)
	fmt.Printf("s3 %T -- str %T (%v)", s3, str, m)

	fmt.Printf("4位数%04d\n", 123)
	s1 := []string{"12", "121"}
	fmt.Println(s1)

	s1 = append(s1, "1")
	fmt.Println(s1)

	//元素类型为map的切片
	var m1 = make([]map[int]string, 1, 10)
	m1[0] = make(map[int]string)
	m1[0][100] = "测试"
	//元素类型为切片的map
	var m2 = make(map[string][]int, 10)
	m2["测试"] = []int{1, 2, 3, 4}
	fmt.Println(m1, m2)

	/*
		 defer通常用来释放函数内部变量。
			1 当defer被声明时，其参数就会被实时解析
			2 defer执行顺序为先进后出
			3 defer可以读取有名返回值
	*/

}

func cReturn() (i int) {
	defer func() { i++ }()
	return 1
}

func Decimal(value float64) float64 {
	value, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", value), 64)
	return value
}
